<!--
 * @Descripttion: 订单列表
 * @Author: xiao li
 * @Date: 2020-12-07 10:50:31
 * @LastEditors: xiao li
 * @LastEditTime: 2022-01-18 10:52:29
-->
<template>
  <div class="lb-order-manage">
    <top-nav />
    <div class="page-main">
      <el-row class="page-search-form">
        <el-form
          @submit.native.prevent
          :inline="true"
          :model="searchForm"
          ref="searchForm"
        >
          <el-form-item label="课程名称" prop="title">
            <el-input
              v-model="searchForm.title"
              placeholder="请输入课程名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="订单状态" prop="pay_type">
            <el-select v-model="searchForm.pay_type" placeholder="请选择">
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="日期">
            <el-date-picker
              v-model="range"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="timestamp"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <lb-button
              type="primary"
              icon="el-icon-search"
              @click="getTableDataList(1)"
              >{{ $t('action.search') }}</lb-button
            >
            <lb-button
              size="medium"
              opType="add"
              icon="el-icon-refresh-left"
              @click="resetForm('searchForm')"
              >{{ $t('action.reset') }}</lb-button
            >
          </el-form-item>
        </el-form>
      </el-row>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
        style="width: 100%"
      >
        <el-table-column
          prop="class"
          width="150"
          label="课程名称"
        ></el-table-column>
        <el-table-column prop="nickName" label="客户昵称"></el-table-column>
        <el-table-column
          prop="mobile"
          label="手机号码"
          width="120"
        ></el-table-column>
        <el-table-column prop="pay_price" label="实收金额"></el-table-column>
        <el-table-column
          prop="order_code"
          width="150"
          label="系统订单号"
        ></el-table-column>
        <el-table-column
          prop="transaction_id"
          width="150"
          label="商户订单号"
        ></el-table-column>
        <el-table-column prop="create_time" width="120" label="下单时间">
          <template slot-scope="scope">
            <div>{{ scope.row.create_time | handleTime(1) }}</div>
            <div>{{ scope.row.create_time | handleTime(2) }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="pay_type" label="订单状态">
          <template slot-scope="scope">
            {{ payType[scope.row.pay_type] }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <div class="table-operate">
              <lb-button
                size="mini"
                type="primary"
                plain
                @click="
                  $router.push(
                    `${appPath}/payclass/orderDetail?id=${scope.row.id}`
                  )
                "
                >{{ $t('action.view') }}</lb-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <lb-page
        :batch="false"
        :page="searchForm.page"
        :pageSize="searchForm.limit"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      >
      </lb-page>
    </div>
  </div>
</template>

<script>
import pubic from '@/utils/public'
export default {
  data () {
    return {
      appPath: '',
      statusOptions: [
        {
          label: '全部',
          value: 0
        },
        {
          label: '待付款',
          value: 1
        },
        {
          label: '已完成',
          value: 2
        },
        {
          label: '已取消',
          value: -1
        }
      ],
      payType: {
        '-1': '已取消',
        1: '待付款',
        2: '已完成'
      },
      loading: false,
      downloadLoading: false,
      centerDialogVisible: false,
      print: false,
      searchForm: {
        page: 1,
        limit: 10,
        title: '',
        pay_type: 0
      },
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      },
      range: '',
      tableData: [],
      printTableData: [],
      total: 0,
      multipleSelection: []
    }
  },
  created () {
    let { path } = this.$route
    this.appPath = path.includes('app/') ? '/app' : ''
    this.getTableDataList()
    this.getSelectOptions()
  },
  methods: {
    resetForm (form) {
      this.$refs[form].resetFields()
      this.range = ''
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    /**
     * @method 搜索订单列表
     */
    getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let { searchForm, range } = this
      // alert(range)
      if (range && range.length > 0) {
        searchForm.start_time = range[0] / 1000
        searchForm.end_time = range[1] / 1000 + 24 * 60 * 60 - 1
      } else {
        searchForm.start_time = ''
        searchForm.end_time = ''
      }
      this.$api.payclassOrderList(searchForm).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.data.data
          this.total = res.data.total
        }
      })
    },
    /**
     * @method 获取下拉菜单的选项值
     */
    getSelectOptions () {
      this.$api.GoodsListSelect().then(res => {
        if (res.code === 200) {
          let { companyOptions, cateOptions } = this
          let { cate, company } = res.data
          this.companyOptions = companyOptions.concat(company)
          this.cateOptions = cateOptions.concat(cate)
        }
      })
    },
    /**
     * @method 跳转详情
     */
    jumpToDetail () {
      this.$router.push()
    },
    /**
     * @method 打印表格
     */
    printTable () {
      this.print = true
      setTimeout(() => {
        this.$print(this.$refs.print)
        this.print = false
      }, 50)
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-order-manage {
  .page-main {
    width: 100%;
    padding: 20px;

    .el-select,
    .el-input-number,
    .el-input {
      width: 200px;
    }
    .el-table {
      .table-goods-info {
        width: 280px;
        height: 80px;
        margin-bottom: 10px;
        font-size: 12px;

        .goods-info-r {
          width: 210px;

          p {
            width: 100%;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }

          .price {
            color: red;
          }
        }

        .el-image {
          min-width: 70px;
          height: 70px;
        }

        &:last-child {
          margin-bottom: 0;
        }
      }
    }
  }
}

.none {
  display: none;
}
</style>
<style media="print">
.none {
  display: block;
}
</style>
